{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "python变量语法：变量名=值\n",
    "语义化命名\n",
    "变量名可以包含字母、数字和“_”\n",
    "区分大小写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scugx 18 True 成都 110\n",
      "scugx 19 True 成都 110\n"
     ]
    }
   ],
   "source": [
    "# 变量\n",
    "name=\"scugx\"\n",
    "age=18\n",
    "gender=True\n",
    "city=\"成都\"\n",
    "telephone='110'\n",
    "print(name,age,gender,city,telephone)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "二、数据类型\n",
    "不可变数据类型\n",
    "string\n",
    "number\n",
    "tuple\n",
    "可变数据类型\n",
    "list\n",
    "set\n",
    "dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "002\n",
      "[11, 13]\n",
      "{10, 12}\n",
      "{'name': 'scugx', 'age': 18, 'telephone': '110'}\n",
      "dict_keys(['name', 'age', 'telephone'])\n",
      "dict_values(['scugx', 18, '110'])\n"
     ]
    }
   ],
   "source": [
    "# 元组\n",
    "names=('001','002') # 元组\n",
    "# names[0] = '003'\n",
    "print(names[-1])\n",
    "# 列表\n",
    "score=[11,13]\n",
    "print(score)\n",
    "# 集合\n",
    "names={10,12}\n",
    "print(names)\n",
    "# 字典\n",
    "students={\n",
    "    \"name\":\"scugx\",\n",
    "    \"age\":18,\n",
    "    \"telephone\":\"110\",\n",
    "}\n",
    "print(students)\n",
    "print(students.keys())\n",
    "print(students.values())\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "三、运算符\n",
    "算术运算符\n",
    "比较运算符\n",
    "赋值运算符\n",
    "位运算符\n",
    "成员运算符\n",
    "身份运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "# 算术运算符\n",
    "print(5%2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "四、切片\n",
    "正向索引：0，1，2\n",
    "反向索引：-1，-2，-3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hlowrd\n",
      "11\n"
     ]
    }
   ],
   "source": [
    "hello=\"hello world\"\n",
    "print(hello[0:len(hello):2])\n",
    "print(len(hello))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1= 1 \n",
      "1*3= 3 2*3= 6 3*3= 9 \n",
      "1*5= 5 2*5=10 3*5=15 4*5=20 5*5=25 \n",
      "1*7= 7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 \n",
      "1*9= 9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 \n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,2):\n",
    "    for j in range(1, i+1):\n",
    "        print(\"{0}*{1}={2:2d}\".format(j,i,i*j),end=\" \")\n",
    "    print()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "五、流程控制\n",
    "条件语句\n",
    "循环语句\n",
    "continue\n",
    "break\n",
    "return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "2550\n",
      "12 13 14 15 0 12\n",
      "1 13\n",
      "2 14\n",
      "3 15\n",
      "12 13 14 15 "
     ]
    }
   ],
   "source": [
    "if 1>2:\n",
    "    print(1)\n",
    "else:\n",
    "    print(2)\n",
    "sum,i=0,0\n",
    "while i <= 100:\n",
    "    sum+=i\n",
    "    i+=2\n",
    "print(sum)\n",
    "#遍历列表\n",
    "score=[12,13,14,15]\n",
    "for e in score:\n",
    "    print(e,end=' ')\n",
    "\n",
    "for i,e in enumerate(score):\n",
    "    print(i,e)\n",
    "\n",
    "for i in range(len(score)):\n",
    "    print(score[i],end=' ')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "六、模块的引用\n",
    "import模块\n",
    "from 模块名称 import 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[12 23 23]\n",
      " [44 56 89]]\n",
      "<class 'numpy.ndarray'>\n",
      "int32\n",
      "6\n",
      "(2, 3)\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "from numpy import array as arr\n",
    "# nums=arr([12,23,23,44,56,89]) # numpy的数组不同之处在于 数组内的元素类型都一样\n",
    "nums=arr([12,23,23,44,56,89]).reshape(2,3) # 转换为2行3列\n",
    "print(nums)\n",
    "print(type(nums))\n",
    "print(nums.dtype)\n",
    "print(nums.size) # 数组的规模，即元素的个数\n",
    "print(nums.shape) # 各个维度的大小\n",
    "print(nums.ndim) # 维度的个数\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "七、练习\n",
    "读取e盘中的所有目录及文件名称\n",
    "求斐波拉契数列第30位数值\n",
    "求1-200之间的所有素数\n",
    "计算20-300之间的奇数和\n",
    "对序列[23,12,3,566,78,90,12]从小到大排序 至少使用三种及以上算法实现\n",
    "\n",
    "抓取他人服务器上的数据并保存到某地"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inj \\\\\n"
     ]
    }
   ],
   "source": [
    "print(R\"inj \\\\\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
